The Linux Kernel HOWTO: Quick Steps - Kernel CompileNext Previous Contents 


2. Quick Steps - Kernel Compile
This section is written by Al Dev (alavoor[AT]yahoo.com) (The latest version of 
this document is at http://www.milkywaygalaxy.freeservers.com. You may want to 
check there for changes). Mirror sites are at - angelfire, geocities. These 
sites have lots of linux goodies and tips. 
Kernel re-compile is required in order to make the kernel very lean and which 
will result in FASTER operating system . It is also required to support any new 
devices. 
2.1 Precautionary Preparations 
Before you build kernel, it is a good idea to do a backup of the system. If you 
had not backed up your system recently then you can do it now. You can use 
commercial backup tools like BRS Backup-Recovery-Software (also in this page you 
can find open-source/freeware backup tools listed under 'Backup and Restore 
Utility'). Backup is just a suggestion and it is not mandatory to do backup 
before building the Linux kernel. 
2.2 For the Impatient 
  Unpack the sources 
  Optional - You can copy the .config file from your old linux kernel source 
  tree to new kernel tree (may save time, if you want to reuse the old 
  settings). 
  make clean 
  make xconfig 
  make dep 
  make 
  make bzImage 
  make modules 
  make install 
  make modules_install 
  configure LILO or GRUB. 
  Optional - make clean (If you want to free up disk space) 
See details of above steps in next section.... 
2.3 Building Kernel - Explanation of Steps 
Details of the steps mentioned in the previous section: 
Note: Below 'bash#' denotes the bash prompt, you should type the commands that 
appear after the 'bash#' prompt. Below are commands tested on Redhat Linux 
Kernel 2.4.7-10, but it should work for other distributions with very minor 
changes. It should also work for older kernel versions like 2.2, 2.0 and 1.3. It 
should also work for future or newer versions of kernel (with little changes - 
let me know). 
  Note: You can have many kernel images on your system. By following the steps 
  below you do not overwrite or damage your existing kernel. These steps are 
  very safe and your current kernel will be intact and will not be touched. 
  Unpack the sources: Login in as 'root' throughout all these steps. Mount 
  Redhat linux cdrom and install the linux kernel source rpm 


bash$ su - root
bash# cd /mnt/cdrom/RedHat/RPMS 
bash# rpm -i kernel-headers*.rpm 
bash# rpm -i kernel-source*.rpm 
bash# rpm -i dev86*.rpm   
bash# rpm -i bin86*.rpm   


  (The bin86*.rpm and 'as86' is required only for OLDER Linux systems like 
  Redhat 5.x. Get Intel assembler 'as86' command from dev86*.rpm on cdrom or 
  from bin86-mandrake , bin86-kondara ). 
  Optional - You can copy the .config file from your old linux kernel source 
  tree to new kernel tree (may save time, if you want to reuse the old 
  settings). 


        bash# cp ../linux-old-tree/.config .



  Clean : 


        bash# cd /usr/src/linux 
        bash# make clean 



  Configure: 
    Start X-windows with 'startx'. If you are not able to start X-window then 
    see next step below. 


        bash# man startx
        bash# startx
        bash# cd /usr/src/linux 
        bash# make xconfig 



    If you are not able to start X-window above then try - 


        bash# export TERM=xterm
        bash# make menuconfig

If you find scrambled display, then use different terminal emulators like vt100,
vt102, vt220 or ansi. The display will be scrambled and will have garbage 
characters in cases where you use telnet to login to remote linux. In such 
cases you should use the terminal emulators like vt100, vt220. 
For example:
        bash# export TERM=vt220
        bash# export TERM=ansi

At a lower level of VT, use: 
        bash# export TERM=vt100
        bash# make menuconfig

If the menuconfig command fails then try -
        bash# make config



  The "make xconfig" or "make menuconfig" brings up a user friendly GUI 
  interface. And "make config" brings up command-line console mode interface. 
  You can load the configuration file from /usr/src/linux/.config (dot config 
  file. Note the dot before config). 
  Within 'make xconfig' you must do these to avoid problems - 
    Select proper CPU type - Pentium 3, AMD K6, Cyrix, Pentium 4, Intel 386, DEC 
    Alpha, PowerPC otherwise kernel will not boot!! 
    Select SMP support - whether single CPU or multiple CPUs 
    Filesystems - Select Windows95 Vfat, MSDOS, NTFS as part of kernel and not 
    as loadable modules. (My personal preference but you are free to pick your 
    own option). 
    Enable the Loadable kernel modules support! With this option you can 
    load/unload the device drivers dynamically on running linux system on the 
    fly. See these man pages 


bash# rpm -i /mnt/cdrom/Redhat/RPMS/modutils*.rpm
bash# man lsmod
bash# man insmod
bash# man rmmod
bash# man depmod
bash# man modprobe



  Save and Exit "make xconfig". All the options which you selected is now saved 
  into configuration file at /usr/src/linux/.config (dot config file). 
  Dep and Clean: And now, do - 


bash# make dep
bash# make clean



  Do make: Read the following file (to gain some knowledge about kernel 
  building. Tip: Use the color editor gvim for better readability. 


bash# gvim -R   /usr/src/linux/arch/i386/config.in 
bash# man less 
bash# less   /usr/src/linux/arch/i386/config.in 
Type 'h' for help and to navigate press i, j, k, l, h or arrow, page up/down keys. 



  Now, give the make command - 



        bash# cd /usr/src/linux
        bash# man nohup
        bash# nohup make bzImage &  
        bash# man tail
        bash# tail -f nohup.out     (.... to monitor the progress) 
This will put the kernel in /usr/src/linux/arch/i386/boot/bzImage 



  bzImage: After bzImage is successful, copy the kernel image to /boot 
  directory. You must copy the new kernel image to /boot directory, otherwise 
  the new kernel MAY NOT boot. 


bash# cp /usr/src/linux/arch/i386/boot/bzImage     /boot/bzImage.myker.26mar2001



  Configure LILO or GRUB : There are two options for boot loading under Redhat 
  Linux - 
    LILO 
    GRUB 
  Configure LILO: Read the manual page on lilo (see also 
  http://www.linuxdoc.org/HOWTO/LILO-crash-rescue-HOWTO.html) and see the sample 
  lilo.conf file. Always give a date extension to the filename, because it tells 
  you when you built the kernel, as shown below: 



bash# man lilo
bash# man lilo.conf
And edit /etc/lilo.conf file and put these lines - 
        image=/boot/bzImage.myker.26mar2001 
        label=myker
        root=/dev/hda1 
        read-only 
You can check device name for 'root=' with the command - 
        bash# df   / 

Now give -
        bash# lilo 
        bash# lilo -q 


  You must re-run lilo even if the entry 'myker' exists, everytime you create a 
  new bzImage. 
  Configure GRUB: GRUB differs from bootloaders such as LILO in that it can lie 
  to Windows and make Windows believe that it's installed on the first partition 
  even if it's not. So you can keep your current Linux system where it is and 
  install Windows on the side. See 
    http://www.tldp.org/HOWTO/Linux+Win9x+Grub-HOWTO/intro.html 
    GNU GRUB http://www.gnu.org/software/grub 
    Redhat Manual. 
    Multiboot-with-GRUB minihowto 
    Grub Manual 
  Reboot the machine and at lilo press tab key and type 'myker' If it boots then 
  you did a good job! Otherwise at lilo select your old kernel, boot and re-try 
  all over again. Your old kernel is still INTACT and SAFE at say 
  /boot/vmlinuz-2.0.34-0.6 
  If your new kernel 'myker' boots and works properly, you can create the boot 
  disk. Insert a blank floppy into floppy drive and - 


bash# cd /usr/src/linux
bash# make bzdisk

See also mkbootdisk -
bash# rpm -i mkbootdisk*.rpm
bash# man mkbootdisk



  LOADABLE MODULES: This step is required ONLY if you had enabled Loadable 
  module support in step 3 above. Loadable module are located in /lib/modules. 
  You MUST do this step if you enabled or disabled any modules, otherwise you 
  will get 'unresolved symbols' errors during or after kernel boot. Check for 
  insmod command which is extensively used for loading the modules. 


bash# cd /usr/src/linux
bash# make modules
bash# make modules_install


  This will copy the modules to /lib/modules directory. For example to load the 
  module /lib/modules/2.4.2-2/kernel/drivers/block/loop.o, you would do : 


bash# man insmod
bash# modprobe loop
bash# insmod loop
bash# lsmod 


  You can set PATH the insmod searches in /etc/modules.conf 
  Clean: Optional - make clean (If you want to free up disk space) 
2.4 Troublshoot Common Mistakes 
The System Hangs at LILO
Sympton: After you build the kernel and reboot, the system hangs just before 
LILO. 
Reason: Probably you did not set the BIOS to pick up the proper Primary Master 
IDE and Secondary Slave IDE hard disk partition. 
Solution: Power on the machine and press DEL key to do setup of the BIOS (Basic 
Input Output system). Select the IDE settings and set proper primary hard disk 
partition and slave drives. When the system boots it looks for the primary IDE 
hard disk and the Master Boot Record partition. It reads the MBR and starts 
loading the Linux Kernel from the hard disk partition. 
No init found
The following mistake is commited very frequently by new users. 
If your new kernel does not boot and you get - 



Warning: unable to open an initial console
Kernel panic: no init found. Try passing init= option to kernel


The problem is that you did not set the "root=" parameter properly in the 
/etc/lilo.conf. In my case, I used root=/dev/hda1 which is having the root 
partition "/". You must properly point the root device in your lilo.conf, it can 
be like /dev/hdb2 or /dev/hda7. 
The kernel looks for the init command which is located in /sbin/init. And /sbin 
directory lives on the root partition. For details see - 



bash# man init



The 'depmod' gives "Unresolved symbol error messages"
When you run depmod it gives "Unresolved symbols". A sample error message is 
given here to demonstrate the case: 



bash$ su - root
bash# man depmod
bash# depmod
depmod: *** Unresolved symbols in /lib/modules/version/kernel/drivers/md/linear.o
depmod: *** Unresolved symbols in /lib/modules/version/kernel/drivers/md/multipath.o
depmod: *** Unresolved symbols in /lib/modules/version/kernel/drivers/md/raid0.o
depmod: *** Unresolved symbols in /lib/modules/version/kernel/drivers/md/raid1.o
depmod: *** Unresolved symbols in /lib/modules/version/kernel/drivers/md/raid5.o



Reason: You did not make modules and install the modules after building the new 
kernel with "make bzImage". 
Solution: After you build the new kernel, you must do: 



bash$ su - root
bash# cd /usr/src/linux
bash# make modules
bash# make modules_install



Kernel Does Not Load Module - "Unresolved symbols" Error Messages
When you boot kernel and system tries to load any modules and you get 
"Unresolved symbol : __some_function_name" then it means that you did not clean 
compile the modules and kernel. It is mandatory that you should do make clean 
and make the modules. Do this - 



        bash# cd /usr/src/linux
        bash# make dep
        bash# make clean
        bash# nohup make bzImage &  
        bash# tail -f nohup.out     (.... to monitor the progress) 
        bash# make modules
        bash# make modules_install



Kernel fails to load a module 
If the kernel fails to load a module (say loadable module for network card or 
other devices), then you may want to try to build the driver for device right 
into the kernel. Sometimes loadable module will NOT work and the driver needs to 
be built right inside the kernel. For example - some network cards do not 
support loadable module feature - you MUST build the driver of the network card 
right into linux kernel. Hence, in 'make xconfig' you MUST not select loadable 
module for this device. 
Loadable modules
You can install default loadable modules with - 
The step given below may not be required but is needed ONLY FOR EMERGENCIES 
where your /lib/modules files are damaged. If you already have the /lib/modules 
directory and in case you want replace them use the --force to replace the 
package and select appropriate cpu architecture. 
For new versions of linux redhat linux 6.0 and later, the kernel modules are 
included with kernel-2.2*.rpm. Install the loadable modules and the kernel with 



        This will list the already installed package.
bash# rpm -qa | grep -i kernel
        
bash# rpm -U --force  /mnt/cdrom/Redhat/RPMS/kernel-2.2.14-5.0.i686.rpm
(or)
bash# rpm -U --force  /mnt/cdrom/Redhat/RPMS/kernel-2.2.14-5.0.i586.rpm
(or)
bash# rpm -U --force  /mnt/cdrom/Redhat/RPMS/kernel-2.2.14-5.0.i386.rpm



This is only for old versions of redhat linux 5.2 and before. Boot new kernel 
and install the loadable modules from RedHat Linux "contrib" cdrom 



bash# rpm -i /mnt/cdrom/contrib/kernel-modules*.rpm 
....(For old linux systems which do not have insmod pre-installed) 



2.5 Post Kernel Building 
After successfully building and booting the Linux kernel, you may be required to 
do these additional steps to make some of the devices to work with Linux. (The 
steps below were tested on Redhat Linux but should work with other distributions 
as well.) 
Video card/Monitor configuration: 
  Please see the video card manual which is usually shipped with the PC. You 
  should look for a "Technical Specifications" page. 
  Please see the monitor's manual and look for a "Technical Specifications" 
  page. 
You can configure the Video card and monitor by using these commands: 


bash$ su - root
bash# man Xconfigurator
bash# /usr/bin/X11/Xconfigurator --help
bash# /usr/bin/X11/Xconfigurator 
bash# /usr/bin/X11/Xconfigurator --expert

See also:
bash# man xf86config
bash# /usr/bin/X11/xf86config


If your card is not detected automatically, then you can use the --expert option 
and select the "Unlisted card". If your monitor is not listed then select the 
generic monitor type SVGA 1024x768. 
Sound card configuration: 
  Connect your external speakers to the sound card's audio port. 
  Connect your CDROM audio wire to sound card's audio 4-pin socket. (Otherwise 
  your cdrom drive will not play the music from your music cd) 
  Refer to HOWTO docs on 'Sound' at http://www.linuxdoc.org 



bash$ su - root
bash# man sndconfig
bash# /usr/sbin/sndconfig


Then start X-window 'KDE desktop' with 'startx' command. Click on 'K 
Start->ControlCenter->SoundServer->General->Test Sound'. This should play the 
test sound. Then click on 'K Start->MultiMedia->SoundMixer->SoundVolumeSlider' 
and adjust the sound volume. 
Network card configuration: 
  Use /sbin/linuxconf 
  Or use KDE control panel 
  Refer to HOWTO docs on 'Networking' at http://www.linuxdoc.org 
Configure Firewall and IP Masquerading : For Linux kernel version 2.4 and above, 
the firewall and IP Masquerading is implemented by NetFilter package. Hence in 
kernel config you should enable Netfilter and run the Firewall/IPMasq script. 
Download the scripts from Firewall-IPMasq scripts , main page of Netfilter is at 
http://netfilter.samba.org. Related materials at firewalling-matures and 
Netfilter-FAQ. 
For kernel version below 2.4 you should install the firewall rpms from 
rpmfind.net or firewall.src.rpm. 
Configuration of other devices: Refer to HOWTO docs relating to your devices at 
http://www.linuxdoc.org
2.6 Sample lilo.conf 
Given below is a sample /etc/lilo.conf file. You should follow the naming 
conventions like ker2217 (for kernel 2.2.17), ker2214 (for kernel 2.2.14). You 
can have many kernel images on the same /boot system. On my machine I have 
something like: 



boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
default=firewall

image=/boot/vmlinuz-2.2.14-5.0
        label=ker2214
        read-only
        root=/dev/hda9

image=/boot/vmlinuz-2.2.17-14
        label=ker2217
        read-only
        root=/dev/hda9

#image=/usr/src/linux/arch/i386/boot/bzImage 
#       label=myker 
#       root=/dev/hda7
#       read-only 

image=/boot/bzImage.myker.11feb2001
        label=myker11feb 
        root=/dev/hda9
        read-only 

image=/boot/bzImage.myker.01jan2001
        label=myker01jan 
        root=/dev/hda9
        read-only 

image=/boot/bzImage.myker-firewall.16mar2001
        label=firewall 
        root=/dev/hda9
        read-only 





Next Previous Contents 